package com.arox.springinaction.integration;

import java.util.Map;

import javax.jms.MapMessage;

import org.apache.log4j.Logger;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.ServiceActivator;

public class InboundHelloWorldJMSMessageProcessor {
    private static final Logger logger = Logger.getLogger(InboundHelloWorldJMSMessageProcessor.class);

    @ServiceActivator
    public void handleIncomingJmsMessage(Message<Map<String, Object>> inboundJmsMessage) throws Throwable {
	Map<String, Object> msg = inboundJmsMessage.getPayload();
	logger.debug(String.format("firstName: %s, lastName: %s, id:%s", msg.get("firstName"), msg.get("lastName"),
		msg.get("id")));
	// you can imagine what we could do here: put
	// the record into the database, call a websrvice,
	// write it to a file, etc, etc
    }
/*
    @ServiceActivator
    public void handleIncomingJmsMessageWithPayloadNotExtracted(Message<javax.jms.Message> msgWithJmsMessageAsPayload)
	    throws Throwable {
	javax.jms.MapMessage jmsMessage = (MapMessage) msgWithJmsMessageAsPayload.getPayload();
	logger.debug(String.format("firstName: %s, lastName: %s, id:%s", jmsMessage.getString("firstName"),
		jmsMessage.getString("lastName"), jmsMessage.getLong("id")));
    }
    */
}
